﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        <select class="form-control " id="region" col="region">
                        </select>
                    </li>
                    <li>
                        <select class="form-control select2" id="searchType" col="searchType">
                            <option value="HuanBaoCode">环保号牌 </option>
                            <option value="OwnerName">所有人 </option>
                            <option value="OwnerTel">联系电话 </option>
                        </select>
                    </li>
                    <li>
                        <input id="keywords" col="keywords" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnInfo" class="btn btn-warning" onclick="showInfoCard()">
                <i class="fa fa-vcard-o"></i>信息采集卡
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        var regionList = top.getDataDict("Region");
        if (regionList) {
            for (var i = 0; i < regionList.length; i++) {
                $('#region').append('<option values="' + regionList[i].DictValue + '">' + regionList[i].DictValue + '</option>');
            }
        }
        initGrid();

    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/YiDongYuan/Mechanics/GetPageListJson")';
        $('#gridTable').ysTable({
            url: queryUrl,
            sortName: 'BaseCreateTime',
            sortOrder: 'Desc',
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'Region', title: '所属县区',width: '80' },
                { field: 'HuanBaoCode', title: '环保号牌', width: '130'  },
                { field: 'OwnerName', title: '所有人', width: '200'  },
                { field: 'OwnerTel', title: '联系电话', width: '130' },
                { field: 'JXDJLX', title: '机械类型', width: '80'  },
                { field: 'JXLB', title: '机械名称', width: '120'  },
                { field: 'PFJD', title: '排放阶段', width: '80'  }
            ],
            singleSelect: true,
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/YiDongYuan/Mechanics/MechanicsForm")' + '?id=' + id,
            width: '800px',
            height: '700px',
            isFull:true,
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    //非道机械设备信息证
    function showInfoCard() {
        var id = 0;
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (!ys.checkRowEdit(selectedRow)) {
            return;
        }
        else {
            id = selectedRow[0].Id;
        }
        ys.openDialog({
            title: '非道机械信息采集卡',
            content: '@Url.Content("~/YiDongYuan/Mechanics/InfoCard")' + '?id=' + id,
            width: '800px',
            height: '700px',
            btn:null,
        });
    }

</script>
